package ch.unifr.dokpe.htmlpicker.urlformater;


import java.util.*;

public class StaticUrlFormater extends AbstractUrlFormater {

/**
* A formater that places in the url a value read in the property file
* The name of the property is passed in the constructor
* @see ch.unifr.dokpe.htmlpicker.urlformater.DefaultUrlFormater#formatUrl(String url, String param, int searchNo)
*/
private String propVal;
private Properties properties;
private String propName;

/**
 * @param propName String the property name
 */

public StaticUrlFormater(String propName) {
	//System.out.println("StaticUrlFormatter: " + propName);
	this.propName = propName;
}

protected void setProperties(Properties properties){
	this.properties = properties;
	if (properties==null)
		throw new RuntimeException("Null Properties in StaticUrlFormater");
}

/**
* @param url url segment holding the string to be replaced by the value of the property
* @param p String not used
* @param i int not used
* @return the formated url segment
*/
public String formatUrl(String url, String p, int i){
	//StringBuffer urlTotal = new StringBuffer();
	//String tmp = url.replaceAll(count_symb, Integer.toString(searchNo));
	//urlTotal.append((searchNo==1?"":connect) + tmp.replaceFirst(param_symb, param));
	String propVal = properties.getProperty(propName);
	//System.out.println("StaticUrlFormatter.formatURL: " + propVal);
	return url.replaceFirst(param_symb, propVal);
	}
 }
